<?php
namespace app\overlord\model;

use app\BaseModel;
use think\facade\Db;

class Content extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_overlord_content';



    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:04
     * @功能说明:内容添加
     */
    public function dataAdd($data){

        $data['create_time'] = time();

        $data['update_time'] = time();

        $res = $this->insert($data);

        return $res;

    }



    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:05
     * @功能说明:内容编辑
     */
    public function dataUpdate($dis,$data){

        $data['update_time'] = time();

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:06
     * @功能说明:列表
     */
    public function dataList($dis,$page){

        $data = $this->where($dis)->order('top desc,id desc')->paginate($page)->toArray();

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:43
     * @功能说明:
     */
    public function dataInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }


    /**
     * @author chenniang
     * @DataTime: 2020-11-26 16:58
     * @功能说明:活动类容
     */
    public function atvContent($atv_id){

        $dis = [

            'a.status' => 1,

            'b.atv_id' => $atv_id
        ];

        $data = $this->alias('a')
                ->join('longbing_card_overlord_content_atv b','a.id = b.content_id')
                ->where($dis)
                ->field('a.*')
                ->group('a.id')
                ->order('a.top desc,a.id desc')
                ->select()
                ->toArray();

        return $data;

    }











}